package com.ctshk.rpc.payment.enums;

import com.ctshk.rpc.payment.strategy.PayStrategy;
import com.ctshk.rpc.payment.strategy.impl.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.payment.enums
 * @Author: hef
 * @CreateTime: 2021-04-20 17:40
 * @Description: 支付方式 code必须和PaymentMethod里面的对应
 */
@Getter
@AllArgsConstructor
public enum PaymentMethodClass {
    ALI_PAY_HK_H5(1, "HK支付宝_H5", AliPayStrategy.class),
    ALI_PAY_CH_H5(2, "CH支付宝_H5", AliPayStrategy.class),
    ALI_PAY_HK_PC(3, "HK支付宝_PC", AliPayStrategy.class),
    ALI_PAY_CH_PC(4, "CH支付宝_PC", AliPayStrategy.class),
    ALI_PAY_HK_APP(5, "HK支付宝_APP", AliPayStrategy.class),
    ALI_PAY_CH_APP(6, "CH支付宝_APP", AliPayStrategy.class),
    WE_CHAT_PAY_NATIVE(7, "微信支付_NATIVE", WeChatPayStrategy.class),
    WE_CHAT_PAY_APP(8, "微信支付_APP", WeChatPayStrategy.class),
    UNIONPAY_ONLINE_PAYMENT_APP(9, "银联在线支付-APP", UnionPayAppStrategy.class),
    UNIONPAY_ONLINE_PAYMENT_WEB(10, "银联在线支付-WEB", UnionPayWebStrategy.class),
    UNIONPAY_ONLINE_PAYMENT_WAP(11, "银联在线支付-WAP", UnionPayWapStrategy.class),
    VISA_MASTERCARD_HOSTED(12, "Visa/MasterCard-托管", MastercardPayHostedStrategy.class),

    ;
    /**
     * 必须和PaymentMethod里面的对应
     */
    private Integer code;
    private String name;
    private Class<? extends PayStrategy> clazz;

    /**
     * 获取class对象
     *
     * @param code
     * @return
     */
    public static Class<? extends PayStrategy> getClassByCode(Integer code) {
        PaymentMethodClass paymentMethodClass = Arrays.stream(PaymentMethodClass.values())
                .filter(enums -> enums.getCode().equals(code)).findFirst().orElse(null);
        if (paymentMethodClass != null) return paymentMethodClass.getClazz();
        return null;
    }
}
